package mqtts

import (
	"gitee.com/ymofen/gobase"
	"log"
)
import "github.com/fhmq/hmq/broker"

type MqttServ struct {
	addr   string
	wsport string
	wspath string
}

func (ms *MqttServ) Start() {

	var config broker.Config
	config.Worker = 1024
	{
		s1, s2 := gobase.Split2Str(ms.addr, ":")
		if len(s1) > 0 {
			config.Host = s1
		}
		if len(s2) == 0 {
			s2 = "1883"
		}
		config.Port = s2
	}

	if len(ms.wsport) > 0 {
		config.WsPort = ms.wsport
		config.WsPath = ms.wspath
		if len(config.WsPath) == 0 {
			config.WsPath = "/mqtts"
		} else {
			_, config.WsPath = gobase.CheckAddPrefix(config.WsPath, "/")
		}
	}

	// 创建一个新的 broker 实例
	b, err := broker.NewBroker(&config)
	if err != nil {
		log.Fatalf("broker.NewBroker error:%v", err)
	}

	b.Start()
}
